//
//  ObligationTableView.m
//  StandardizedProduct
//
//  Created by 宁宁 on 16/6/23.
//  Copyright © 2016年 ym. All rights reserved.
//

#import "ObligationTableView.h"

#import "OrderHeaderView.h"//页眉
#import "ObligationFooterView.h"//页脚
#import "OrderFooterTotalString.h"//页脚合计String
#import "OrderDetailTableViewCell.h"//Cell


@implementation ObligationTableView 
{
    //UITableView *_tableView;
    
//    EnterPasswordView *_enterPasswordView;
}

static NSString *const OrderDetailTableViewCellID = @"OrderDetailTableViewCell";

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _obligationTableView= [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 94)style:UITableViewStyleGrouped];
        _obligationTableView.delegate = self;
        _obligationTableView.dataSource = self;
        _obligationTableView.separatorColor = [UIColor clearColor];
        _obligationTableView.showsVerticalScrollIndicator = NO;//去掉滑动竖条
        [self addSubview:_obligationTableView];
        [self registerTableView];
    }
    return self;
}
#pragma mark === 注册TableView ===
- (void)registerTableView{
    //注册自定义cell
    [_obligationTableView registerNib:[UINib nibWithNibName:@"OrderDetailTableViewCell" bundle:nil] forCellReuseIdentifier:OrderDetailTableViewCellID];
}

#pragma mark === TableViewDelegate ===
//section数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _obligationArray.count;
}
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
//Reusable
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OrderDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:OrderDetailTableViewCellID];
    cell.goodsImage.backgroundColor = [UIColor yellowColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
//页眉视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    OrderHeaderView *headView = [[[NSBundle mainBundle] loadNibNamed:@"OrderHeaderView" owner:nil options:nil] lastObject];
    headView.merchantImage.backgroundColor = [UIColor yellowColor];
    return headView;
}
//页脚视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    ObligationFooterView *footView = [[[NSBundle mainBundle] loadNibNamed:@"ObligationFooterView" owner:nil options:nil] lastObject];
    //页脚合计赋值
    footView.total.attributedText = [OrderFooterTotalString AttributedStringWithNum:@2 andTotal:@"200.00" andFreight:@"5.00"];
    //更多
    [footView.more addTarget:self action:@selector(more:) forControlEvents:UIControlEventTouchUpInside];
    //取消订单
    [footView.cancelOrder addTarget:self action:@selector(cancelOrder:) forControlEvents:UIControlEventTouchUpInside];
    //付款
    [footView.payment addTarget:self action:@selector(payment:) forControlEvents:UIControlEventTouchUpInside];
    return footView;
}
//cell高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return WIDTH / 7 * 2;
}
//页眉高
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
//页脚高
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 100;
}
//选择cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    _cellDidSelected(@"待付款" , indexPath.section,indexPath.row);
    

}

#pragma mark === 更多 ===
- (void)more:(UIButton *)button{
    NSLog(@"更多");
}
#pragma mark === 取消订单 ===
- (void)cancelOrder:(UIButton *)button{
    NSLog(@"取消订单");
}
#pragma mark === 付款 ===
- (void)payment:(UIButton *)button{
    NSLog(@"付款");
}
@end
